package com.face.server.controller;

import com.alibaba.fastjson.JSONObject;
import com.face.server.service.UtileService;
import com.mongodb.gridfs.GridFSDBFile;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author jsh
 */
@Controller
@RequestMapping("file")
public class FileController {

    @Autowired
    UtileService utileService;

    /**
     * 不进行图片判断
     */
    @GetMapping("{fileId}")
    void showFile(HttpServletResponse response,
                  @PathVariable String fileId) throws IOException {
        GridFSDBFile fsFile = utileService.getFile(fileId);
        OutputStream outputStream = response.getOutputStream();
        fsFile.writeTo(outputStream);
    }


    /**
     * 不进行图片判断
     */
    @GetMapping("{fileId}/data")
    @ResponseBody
    GridFSDBFile showFileDate(@PathVariable String fileId) throws IOException {
        return utileService.getFile(fileId);
    }


}


